/**
 * @param {number} n
 * @return {number}
 */
var numTrees = function (n) {
  //状态数组dp
  const dp = new Array(n + 1).fill(0)

  //初始化状态数组dp
  dp[0] = 1
  dp[1] = 1

  //状态转移方程：dp[n] = Σ dp[i] * dp[n - 1 - i]，i = 0 到 n - 1
  for (let i = 2; i <= n; i++) {
    for (let j = 0; j < i; j++) {
      dp[i] += dp[j] * dp[i - 1 - j]
    }
  }
  //返回结果dp[n]
  return dp[n]
};
console.log(numTrees(3))